#include "cShader.h"

int cShader::Init(char * fileVertexShader, char * fileFragmentShader)
{
	vertexShader = esLoadShader(GL_VERTEX_SHADER, fileVertexShader);

	if ( vertexShader == 0 )
		return -1;

	fragmentShader = esLoadShader(GL_FRAGMENT_SHADER, fileFragmentShader);

	if ( fragmentShader == 0 )
	{
		glDeleteShader( vertexShader );
		return -2;
	}

	program = esLoadProgram(vertexShader, fragmentShader);

	//finding location of uniforms / attributes
	positionAttribute = glGetAttribLocation(program, "a_posL");
	texCoordAttribute = glGetAttribLocation(program, "a_uv");
	mvpMatrixUniform = glGetUniformLocation(program, "u_mvp");
	skyDomeUniform = glGetUniformLocation(program, "u_samplerCubeMap");
	textureUniform = glGetUniformLocation(program, "u_texture");
	Terrain_heightmap = glGetUniformLocation(program,"u_heightmap");
	Terrain_grass = glGetUniformLocation(program,"u_grass");
	Fire = glGetUniformLocation(program,"u_fire");
	Fire_map = glGetUniformLocation(program,"u_firemap");
	Fire_mask = glGetUniformLocation(program,"u_firemask");
	Uniformincrease=glGetUniformLocation(program,"increase");
	normalAttribute = glGetAttribLocation(program,"a_normal");
	matTransposeInverseUniform = glGetUniformLocation(program,"u_matTransposeInverseViewModel");
	matViewModel = glGetUniformLocation(program,"matViewModel");
	Camera_Position =glGetUniformLocation(program,"Camera_Position");
	u_NormalMap = glGetUniformLocation(program,"u_NormalMap");
	u_W=glGetUniformLocation(program,"u_W");
	a_normalL = glGetAttribLocation(program, "a_normalL");
	a_bitangentL = glGetAttribLocation(program, "a_bitangentL");
	a_tangentL=glGetAttribLocation(program, "a_tangentL");
	teapot = glGetUniformLocation(program, "teapot");
	step = glGetUniformLocation(program, "step");
	if (program == 0)
		return 0;

	return program;
}

cShader::~cShader()
{
	glDeleteProgram(program);
	glDeleteShader(vertexShader);
	glDeleteShader(fragmentShader);
}